package com.loongtech.bi.manager.player;

import com.loongtech.bi.entity.player.EntityPcu;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PcuManager extends ManagerQueryCacheBase<EntityPcu> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 根据开始结束时间查询某个维度的数值
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getPcuByAllKind(Date dateStart, Date dateEnd, String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select date_format(day,'%Y-%m-%d'),pcu from EntityPcu where day>=:dayStart and day<=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' and pcu is not null order by day desc", "dayStart", dateStart, "dayEnd", dateEnd);
	}

    /**
     * 根据开始结束时间查询所有维度的数值
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public List<EntityPcu> getPcuByAllKind(Date dateStart, Date dateEnd) {
        return findByQuery("from EntityPcu where day>=:dayStart and day<=:dayEnd and pcu is not null order by day", "dayStart", dateStart, "dayEnd", dateEnd);
    }

    /**
     * 根据开始结束时间查询所有维度的数值
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public List<EntityPcu> getPcuByAllKind2(Date dateStart, Date dateEnd) {
        return findByQuery("from EntityPcu where day>=:dayStart and day<=:dayEnd and serverid='0' and pcu is not null order by day", "dayStart", dateStart, "dayEnd", dateEnd);
    }

	/**
	 * 根据platformid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getPcuGroupByPlatform(Date dateStart, Date dateEnd) {
		return findByQuery("select platformid,max(pcu) from EntityPcu where day>=:dayStart and day<=:dayEnd and platformid != '0' and pcu is not null group by platformid", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据channelid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getPcuGroupByChannel(Date dateStart, Date dateEnd) {
		return findByQuery("select channelid,max(pcu) from EntityPcu where day>=:dayStart and day<=:dayEnd and channelid != '0' and pcu is not null group by channelid", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据serverid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getPcuGroupByServer(Date dateStart, Date dateEnd) {
		return findByQuery("select serverid,max(pcu) from EntityPcu where day>=:dayStart and day<=:dayEnd and serverid != '0' and pcu is not null group by serverid", "dayStart", dateStart, "dayEnd", dateEnd);
	}
}
